package controllers

import (
	"github.com/gin-gonic/gin"
	"go.didapinche.com/foundation/apisix-dashboard/internal/pkg/constans"
	"go.didapinche.com/foundation/apisix-dashboard/internal/pkg/http"
	"go.didapinche.com/uic"
)

func InitControllersFn(
	controller *UpstreamController,
	consumerController *ConsumerController,
	routeController *RouteController,
	serviceController *ServiceController,
	envController *EnvController,
	uic *uic.Api,
) http.InitControllers {
	return func(r *gin.Engine) {
		{
			r.GET("/upstream/:id/:env", uic.AuthLogin(), envController.AuthEnv, controller.Get)
			r.GET("/upstreams/:env", uic.AuthLogin(), envController.AuthEnv, controller.List)
			r.POST("/upstream/:env", uic.AuthPerm(constans.AppOperatePerm), envController.AuthEnv, controller.Create)
			r.PUT("/upstream/:id/:env", uic.AuthPerm(constans.AppOperatePerm), envController.AuthEnv, controller.Update)
			r.DELETE("/upstream/:id/:env", uic.AuthPerm(constans.AppOperatePerm), envController.AuthEnv, controller.Delete)
			r.GET("/upstream_name/:env", uic.AuthLogin(), envController.AuthEnv, controller.GetName)
			r.POST("/upstream_syn", uic.AuthPerm(constans.AppOperatePerm), controller.Syn)
		}

		{
			r.GET("/route/:id/:env", uic.AuthLogin(), envController.AuthEnv, routeController.Get)
			r.GET("/routes/:env", uic.AuthLogin(), envController.AuthEnv, routeController.List)
			r.POST("/route/:env", uic.AuthPerm(constans.AppOperatePerm), envController.AuthEnv, routeController.Create)
			r.PUT("/route/:env", uic.AuthPerm(constans.AppOperatePerm), envController.AuthEnv, routeController.Update)
			r.DELETE("/route/:id/:env", uic.AuthPerm(constans.AppOperatePerm), envController.AuthEnv, routeController.Delete)
			r.GET("/route_name/:env", uic.AuthLogin(), envController.AuthEnv, routeController.GetName)
			r.POST("/route_syn", uic.AuthPerm(constans.AppOperatePerm), routeController.Syn)
		}

		{
			r.GET("/consumer/:id/:env", uic.AuthLogin(), envController.AuthEnv, consumerController.Get)
			r.GET("/consumers/:env", uic.AuthLogin(), envController.AuthEnv, consumerController.List)
			r.POST("/consumer/:env", uic.AuthPerm(constans.AppOperatePerm), envController.AuthEnv, consumerController.Create)
			r.PUT("/consumer/:env", uic.AuthPerm(constans.AppOperatePerm), envController.AuthEnv, consumerController.Update)
			r.DELETE("/consumer/:id/:env", uic.AuthPerm(constans.AppOperatePerm), envController.AuthEnv, consumerController.Delete)
			r.GET("/consumer_name/:env", uic.AuthLogin(), envController.AuthEnv, consumerController.GetName)
			r.POST("/consumer_syn", uic.AuthPerm(constans.AppOperatePerm), consumerController.Syn)
		}

		{
			r.GET("/service/:id/:env", uic.AuthLogin(), envController.AuthEnv, serviceController.Get)
			r.GET("/services/:env", uic.AuthLogin(), envController.AuthEnv, serviceController.List)
			r.POST("/service/:env", uic.AuthPerm(constans.AppOperatePerm), envController.AuthEnv, serviceController.Create)
			r.PUT("/service/:env", uic.AuthPerm(constans.AppOperatePerm), envController.AuthEnv, serviceController.Update)
			r.DELETE("/service/:id/:env", uic.AuthPerm(constans.AppOperatePerm), envController.AuthEnv, serviceController.Delete)
			r.GET("/service_name/:env", uic.AuthLogin(), envController.AuthEnv, serviceController.GetName)
			r.POST("/service_syn", uic.AuthPerm(constans.AppOperatePerm), serviceController.Syn)
		}

	}
}
